package com.his.finance.controller;

import com.his.common.verification.group.Insert;
import com.his.config.annotation.CurrentUser;
import com.his.finance.service.FinInvoiceStoreService;
import com.his.finance.vo.FinInvoiceStoreVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value="/api/finance")
public class FinanceController extends ResultBaseController {
    private final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Resource
    private FinInvoiceStoreService finInvoiceStoreService;

    /**************************************新增发票******************************************/
    @PostMapping(value="/voicestore_add.do")
    public ResultUtil voicestore_add(@CurrentUser DictEmployee employee ,@Validated({Insert.class}) @RequestBody FinInvoiceStoreVo finInvoiceStoreVo){
        try {
            finInvoiceStoreService.insertFinInvoiceStore(employee,finInvoiceStoreVo);
            return this.success("新增发票成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/voicestore_select.do")
    public ResultUtil voicestore_select(@CurrentUser DictEmployee employee){
        try {
            return this.success("查询当前票号成功", finInvoiceStoreService.selectFinInvoiceStoreNum(employee));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/voicestore_update.do")
    public ResultUtil voicestore_update(@CurrentUser DictEmployee employee ,@RequestBody FinInvoiceStoreVo finInvoiceStoreVo){
        try {
            finInvoiceStoreService.updateFinInvoiceStore(employee,finInvoiceStoreVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

}
